using IQIGame.Onigao.Framework;
using IQIGame.Onigao.Framework.Serialization;

namespace IQIGame.Onigao.Game
{
    public static class CFSMSerializeUtil
    {
        public static object ReadValueByType(ByteBuf buf, CFSMParamType type)
        {
            if (type == CFSMParamType.Bool)
            {
                return buf.ReadBool();
            }
            else if (type == CFSMParamType.Int)
            {
                return buf.ReadInt();
            }
            else if (type == CFSMParamType.Float)
            {
                return buf.ReadFloat();
            }
            else if (type == CFSMParamType.String)
            {
                return buf.ReadString();
            }
            else
            {
                LogGame.LogError("反序列化错误，非法的类型：" + type);
                return null;
            }
        }

        public static void WriteValueByType(ByteBuf buf, CFSMParamType type, object value)
        {
            if (type == CFSMParamType.Bool)
            {
                buf.WriteBool((bool)value);
            }
            else if (type == CFSMParamType.Int)
            {
                buf.WriteInt((int)value);
            }
            else if (type == CFSMParamType.Float)
            {
                buf.WriteFloat((float)value);
            }
            else if (type == CFSMParamType.String)
            {
                buf.WriteString((string)value);
            }
            else
            {
                LogGame.LogError("序列化错误，非法的类型：" + type);
            }
        }
    }
}
